﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_Modes;
using Zor_DAL;
using Zor_Tools;

namespace Zor_Bll
{
    public class Users_Bll
    {
        public static List<Users> GetUserList()
        {
            return Users_DAL.GetUserList();
        }
        public static Users GetUserById(int id)
        {
            return Users_DAL.GetUsersById(id);
        }

        public static BaseAnswer InserUsers( Users us)
        {
            BaseAnswer bar = Users_DAL.InserUsers(us);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "新增成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "新增失败，请重试！";

            return bar;
        }

        public static BaseAnswer UpdateUsers(Users us)
        {
            BaseAnswer bar = Users_DAL.UpdateUses(us);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "修改成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "删除失败，请重试！";
            return bar;
        }

        public static BaseAnswer DeleteUsers(int[] ids)
        {
            BaseAnswer bar = Users_DAL.DelteUsers(ids);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "删除成功！";
            else if(bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "删除失败，请重试！";
            return bar;
        }


        /// <summary>
        /// 用户登陆
        /// </summary>
        /// <returns></returns>
        public static BaseAnswer GetUserByNameAndPass(Users uslogin) 
        {
            BaseAnswer bar = new BaseAnswer();
            Users us = Users_DAL.GetUserByNameAndPass(uslogin);
            if (us == null)
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "用户名密码错误！";

            }
            else if (us.User_UserName == us.User_UserName && us.User_Password == uslogin.User_Password)
            {
                bar.User = us;
                bar.AnswerType = BaseAnswer.Answers.Succee;
                bar.AnswerMeg = "登录成功！";
            }
            else 
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "用户名密码错误！";
            }

            return bar;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="sqlWhere"></param>
        /// <returns></returns>
        public static List<Users> GetUserList(string sqlWhere)
        {
            return Users_DAL.GetUserList(sqlWhere);
        }


        public static BaseAnswer UpdateUsersPassWord(Users us) 
        {
            BaseAnswer bar = Users_DAL.UpdateUsersPassWord(us);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "修改成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "删除失败，请重试！";
            return bar;
        }
    }
}
